package repo

import (
	"app-box/models/tables"

	"gorm.io/gorm"
)

type UserRepo struct {
	BaseRepo
}

func NewUserRepo(DB *gorm.DB) *UserRepo {
	var repo = new(UserRepo)
	repo.DB = DB
	return repo
}

func (repo *UserRepo) GetUserByUserName(userName string, user *tables.User) error {
	return repo.DB.First(user, "user_name", userName).Error
}

func (repo *UserRepo) GetUserByEmployeeNumber(employeeNumber string, user *tables.User) error {
	return repo.DB.First(user, "employee_number", employeeNumber).Error
}

func (repo *UserRepo) InsertUser(user *tables.User) error {
	if err := repo.DB.Create(user).Error; err != nil {
		return err
	}
	return nil
}
